package com.veterinaria.dao;

import java.io.Reader;
import java.util.ArrayList;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.veterinaria.bean.HorarioBean;
import com.veterinaria.services.HorarioService;

public class HorarioDAO implements HorarioService{

	SqlSessionFactory sqlmapper= null;{
	   	 try {
				
			
	   	 Reader reader = Resources.getResourceAsReader("ConfiguracionIbatis.xml");
	   	 
	   	 sqlmapper =new  SqlSessionFactoryBuilder().build(reader);
	   	 } catch (Exception e) {
					e.printStackTrace();
				}
	    }
	
	@Override
	public ArrayList<HorarioBean> listarHorarios() throws Exception {
		
		ArrayList<HorarioBean> lista=new ArrayList<>();
		 SqlSession session = sqlmapper.openSession();		
			try {			
				lista= (ArrayList<HorarioBean>)session.selectList("horarioxml.listarhorarios");			
			} catch (Exception e) {
				e.printStackTrace();
			}finally{ session.close();}
			
			return lista;
	}

}
